﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Collections;
using System.Configuration;

namespace HtmlSanitizer
{
    [XmlRoot("TagsConfiguration")]
    public class TagsConfiguration
    {
        #region Private Fields
        private static TagsConfiguration instance = null;
        public XmlSerializableDictionary<string, Tag> Tags = new XmlSerializableDictionary<string, Tag>();
        #endregion

        #region Constructors
        private TagsConfiguration() { }
        public static TagsConfiguration Instance
        {
            get
            {
                if (instance == null)
                    LoadTags();

                return instance;
            }
        }
        #endregion

        #region Private Members
        private static void LoadTags()
        {
            string tagsConfigPath = ConfigurationSettings.AppSettings["TagsConfigPath"];

            XmlSerializer serializer = new XmlSerializer(typeof(TagsConfiguration));
            FileStream fs = new FileStream(tagsConfigPath, FileMode.Open);
            instance = (TagsConfiguration)serializer.Deserialize(fs);
            fs.Close();
        }
        #endregion
    }
}
